import Vue from 'vue'

export const store = Vue.observable({
	url: {},
	user: {},
	temporary: null
});
export const mutations = {
	url(data) {
		store.url = data;
	},
	user(data) {
		store.user = data;
	},
	temporary(data) {
		store.temporary = data;
	}
}
export default {
	store,
	mutations
}

//刷新 把数据保存到 localStorage
window.addEventListener('beforeunload', () => {
	localStorage.setItem('url', JSON.stringify(store.url));
	localStorage.setItem('user', JSON.stringify(store.user));
});
//从 localStorage 取到数据
mutations.url(JSON.parse(localStorage.getItem('url')));
mutations.user(JSON.parse(localStorage.getItem('user')));
//删除 localStorage 相关
/* localStorage.removeItem('url');
localStorage.removeItem('user'); */
